// stores/counter.js
import { defineStore } from 'pinia'

const systemInfo = uni.getSystemInfoSync()
console.log('systemInfo', systemInfo, systemInfo.screenHeight - systemInfo.safeArea?.bottom)

export const useTabbarStore = defineStore('tabbar', {
  state: () => {
    return {
		height: 100, // rpx
		paddingBottom: systemInfo?.safeArea?.bottom ? systemInfo.screenHeight - systemInfo.safeArea.bottom : 0, // px
		currentId: 'home',
		tabbarList: [
			{
				id: 'home',
				name: '首页',
				icon: 'home',
				activeIcon: 'home-fill'
			},{
				id: 'scan',
				icon: 'scan',
				prominent: true,
				activeHandler: () => {
					// uni.scanCode({
					// 	scanType: ['qrCode'],
					// 	success: (res) => {
					// 		console.log('条码类型：' + res.result);
					// 	}
					uni.navigateTo({
						url: '/pages/charging/charging'
					})
				}
			},{
				id: 'account',
				activeIcon: 'account-fill',
				name: '我的',
				icon: 'account',
			}
		]
	}
  },
  getters: {
	  occupyHeight(state) {// rpx
		  let deviceWidth = systemInfo.windowWidth; //获取设备屏幕宽度
		  let paddingBottomRpx = Math.floor((750 / deviceWidth) * Number(state.paddingBottom))
		  return state.height + paddingBottomRpx
	  }
  },
  // 也可以这样定义
  // state: () => ({ count: 0 })
  actions: {
    increment() {
      this.count++
    },
  },
})